package com.example.zzl.view.fragment.ShareOrderFragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zzl.R;
import com.example.zzl.view.BaseFragment;
import com.example.zzl.view.fragment.ShareOrderFragment.adapter.ShareFragmentViewpager;
import com.example.zzl.view.fragment.ShareOrderFragment.fragment.Choiceness;
import com.example.zzl.view.fragment.ShareOrderFragment.fragment.Mine;
import com.example.zzl.view.fragment.ShareOrderFragment.fragment.Newest;

import java.util.ArrayList;
import java.util.List;


public class ShareOrderFragment extends BaseFragment {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private ShareFragmentViewpager adapter;
    private List<Fragment> fragmentList;
    private List<String> titlelist;
    private Choiceness choiceness;
    private Newest newest;
    private Mine mine;
    private Toolbar toolbar;


    public static ShareOrderFragment newInstance(String data) {

        Bundle args = new Bundle();
        args.putString("data", data);
        ShareOrderFragment fragment = new ShareOrderFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup conainer,
                             Bundle savedInstanceState) {
View view=View.inflate(getContext(),R.layout.fragment_share_order,null);

        tabLayout=(TabLayout)view.findViewById(R.id.tab_share_title);
        viewPager=(ViewPager)view.findViewById(R.id.share_viewpagger);

        toolbar=(Toolbar)view.findViewById(R.id.share_toolbar);
        //替换之前的ActionBar
//getContext().setSupportActionBar(toolbar);

init();
        return view;
    }



    private void init() {

        choiceness=new Choiceness();
        newest=new Newest();
        mine=new Mine();

        fragmentList=new ArrayList<>();
        fragmentList.add(choiceness);
        fragmentList.add(newest);
        fragmentList.add(mine);

        titlelist=new ArrayList<>();
        titlelist.add("精选");
        titlelist.add("最新");
        titlelist.add("我的");

        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.addTab(tabLayout.newTab().setText(titlelist.get(0)));
        tabLayout.addTab(tabLayout.newTab().setText(titlelist.get(1)));
        tabLayout.addTab(tabLayout.newTab().setText(titlelist.get(2)));

        adapter=new ShareFragmentViewpager(getFragmentManager(),fragmentList,titlelist);

        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);

    }

}
